﻿using Corina.Datamodel.Base;
using Corina.Datamodel.Interface;
using Corina.Enumerations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Corina.Datamodel.Entities
{
    [XmlTypeAttribute(Namespace = "http://tempuri.org/")]
    public class DeviceMessageInfo : DatamodelEntity, IDeviceMessage
    {
        #region Fields
        private int _id;
        private string _deviceSn;
        private string _content;
        private string _proofValue;
        private DateTime _recievedTime = DateTime.Now;
        private TransTypeValue _transtype = TransTypeValue.TCP;
        private int _smsId = 0;
        private bool _isAnalysed = false;
        private string _mobileOrIP;
        private string _md5Code;
        private DateTime _measureTime = DateTime.Now;
        #endregion

        #region Properties
        /// <summary>
        /// 编号
        /// </summary>
        public int Id
        {
            get { return _id; }
            set
            {
                _id = value;
                RaisePropertyChanged(() => Id);
            }
        }
        
        /// <summary>
        /// 设备序列号
        /// </summary>
        public string DeviceSn
        {
            get { return _deviceSn; }
            set
            {
                _deviceSn = value;
                RaisePropertyChanged(() => DeviceSn);
            }
        }
        
        /// <summary>
        /// 消息内容
        /// </summary>
        public string Content
        {
            get { return _content; }
            set
            {
                _content = value;
                RaisePropertyChanged(() => Content);
            }
        }

        /// <summary>
        /// 机器校验值
        /// </summary>
        public string ProofValue
        {
            get { return _proofValue; }
            set
            {
                _proofValue = value;
                RaisePropertyChanged(() => ProofValue);
            }
        }
        
        /// <summary>
        /// 接收时间
        /// </summary>
        public DateTime RecievedTime
        {
            get { return _recievedTime; }
            set
            {
                _recievedTime = value;
                RaisePropertyChanged(() => RecievedTime);
            }
        }
        
        /// <summary>
        /// 传输方式
        /// </summary>
        public TransTypeValue TransType
        {
            get { return _transtype; }
            set
            {
                _transtype = value;
                RaisePropertyChanged(() => TransType);
            }
        }
        
        /// <summary>
        /// 短信编号
        /// </summary>
        public int SmsId
        {
            get { return _smsId; }
            set
            {
                _smsId = value;
                RaisePropertyChanged(() => SmsId);
            }
        }

        /// <summary>
        /// 是否已解析
        /// </summary>
        public bool IsAnalysed
        {
            get { return _isAnalysed; }
            set
            {
                _isAnalysed = value;
                RaisePropertyChanged(() => IsAnalysed);
            }
        }

        /// <summary>
        /// 获取或设置设备IP地址或设备SMS模块手机号码
        /// </summary>
        public string MobileOrIP
        {
            get { return _mobileOrIP; }
            set
            {
                _mobileOrIP = value;
                RaisePropertyChanged(() => MobileOrIP);
            }
        }

        public string Md5Code {
            get { return _md5Code; }
            set {
                _md5Code = value;
                RaisePropertyChanged(() => Md5Code);
            }
        }

        public DateTime MeasureTime
        {
            get { return _measureTime; }
            set {
                _measureTime = value;
                RaisePropertyChanged(() => MeasureTime);
            }
        }
        #endregion

        protected override IEnumerable<DatabaseColumn> InitColumns()
        {
            yield return new DatabaseColumn("Id", true);
            yield return new DatabaseColumn("DeviceSn");
            yield return new DatabaseColumn("Content");
            yield return new DatabaseColumn("ProofValue");
            yield return new DatabaseColumn("RecievedTime");
            yield return new DatabaseColumn("TransType");
            yield return new DatabaseColumn("SmsId");
            yield return new DatabaseColumn("IsAnalysed");
            yield return new DatabaseColumn("MobileOrIP");
            yield return new DatabaseColumn("Md5Code");
            yield return new DatabaseColumn("MeasureTime");
        }
    }
}